package com.wfit.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Base64;

public class LoginCodeUtil {



    public static void main(String[] args) {
        try {
            byte[] imageData = readImageFile("E:\\heimaTD\\th.jfif");
            String base64Image = convertToBase64(imageData);
            String imageUrl = buildImageUrl(base64Image);
            System.out.println(imageUrl);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static byte[] readImageFile(String filePath) throws IOException {
        File file = new File(filePath);
        FileInputStream fis = new FileInputStream(file);
        byte[] imageData = new byte[(int) file.length()];
        fis.read(imageData);
        fis.close();
        return imageData;
    }

    public static String convertToBase64(byte[] imageData) {
        return Base64.getEncoder().encodeToString(imageData);
    }

    public static String buildImageUrl(String base64Image) {
        return "data:image/png;base64," + base64Image;
    }
}
